#include "SocketClient.h"
#include <iostream>

using namespace std;

SocketClient::SocketClient(const char *ip, int port) : Socket(port)
{
  _info = gethostbyname(ip);
  if(!_info)
    {
      cerr << "Couldn't get host ip" << endl;;
      exit(1);
    }
  _ip = ntohl(* (uint32_t *)_info->h_addr);
  _addr.sin_family = AF_INET;
  _addr.sin_addr.s_addr = htonl(_ip);
  _addr.sin_port = htons(_port);

  _sock = socket(PF_INET, SOCK_STREAM, 0);
  if(_sock < 0)
    {
      perror("Couldn't create socket");
      exit(1);
    }

  if(connect(_sock, (struct sockaddr *) &_addr, sizeof(_addr)))
    {
      perror("Coudln't connect ");
      exit(1);
    }
}

SocketClient::~SocketClient(){}
